home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Set / examples / ex_Set.C next >
C/C++ Source or Header  |  1992-06-24  |  2KB  |  42 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/String.h>            // COOL String class
  14. #include <cool/Set.h>                // COOL Set class
  15.  
  16. #include <cool/Set.C>
  17. DECLARE CoolSet<CoolString>;            // Declare CoolSet of CoolStrings
  18. IMPLEMENT CoolSet<CoolString>;            // Implement CoolSet of CoolStrings
  19.  
  20. Boolean my_compare (const CoolString& s1, const CoolString& s2) {
  21.   return ((strcmp (s1, s2) == 0) ? TRUE : FALSE);
  22. }
  23.  
  24. static CoolString color_table[] = { "RED", "YELLOW", "PINK", "GREEN",
  25.                     "ORANGE", "PURPLE", "BLUE" };
  26.  
  27. int main (void) {
  28.   CoolSet<CoolString> a(5), b(5);        // Declare two CoolSet objects
  29.   a.set_compare (&my_compare);            // Establish compare function
  30.   for (int i = 0; i < 5; i++) {            // For each color defined
  31.     a.put (color_table[i]);            // Add object to first CoolSet
  32.     b.put (color_table[6-i]);            // Add end object to second CoolSet
  33.   }
  34.   cout << "Set A contains: " << a;         // Elements of CoolSet 1
  35.   cout << "Set B contains: " << b;         // Elements of CoolSet 2
  36.   cout << "A | B: " << (a | b);            // Display union
  37.   cout << "A & B: " << (a & b);            // Display intersection
  38.   cout << "A ^ B: " << (a ^ b);            // Display XOR
  39.   cout << "A - B: " << (a - b);            // Display difference
  40.   return (0);                    // Exit with OK status
  41. }
  42.